$(document).ready(function() {

	//回车模糊查询
	searchEvent();
	//初始化数据
	init(1);
});
	
//默认加载  
function init(pageNo){
	//获取信息列表
	var orderId=getvl("id");
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/account/jpa/page?pageNum="+pageNo+"&pageSize="+pageSize+"&search="+$('#search').val()+"&isRegister="+1+"&userType="+2,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data.list,function(i,n){
					var rideId = n.user.id;
					if(n.user.realName==null){
						n.user.realName="";
					}
					var thislist = 
					'	<tr>'+
					'		<td>'+(i+1)+'</td>'+					
					'		<td>'+n.user.secondId+'</td>'+
					'		<td>'+n.user.realName+'</td>'+
					'		<td>'+n.user.phone+'</td>'+
					'		<td>'+n.allMoney+'</td>'+
					'		<td>'+n.depositMoney+'</td>'+
					'		<td>'+
								'<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="sendOrder('+rideId+','+orderId+')">手动指派</a>'+
					'		</td>'+
					'	</tr>';
					$('#thislist').append(thislist);										
				});
				$('#thiscount').text(data.data.total);
				$("#pager").pager({
					pagenumber: pageNo, 
					pagecount:data.data.pages,
					totalcount:data.data.total,
					buttonClickCallback: PageClick
				}); 											
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});

}

function sendOrder(rideId,orderId){
	$.ajax({
	    url: urlcore + "/api/user/sendOrderToRider?rideId="+rideId+"&orderId="+orderId,
	    type: "get",
	    dataType: 'json',
	    contentType: "application/json;charset=utf-8",
	    success:function(data){
	        if (data.success == true) {
		        	alert(data.msg);
		          window.location.href = "order_list.html?status="+-3;                
	        } else if (data.code == 'OVERTIME'){
	            var thisUrl = window.location.href;
	            if (thisUrl.indexOf('login.html') <= -1) {
	                top.window.location.href="login.html";
	            }
	        } else {
	            alert(data.msg);
	        }
	    },
	    error:function() {
	        /* Act on the event */
	        alert("error");
	    }
	});
}

//回调函数  
PageClick = function(pageclickednumber) {  
    init(pageclickednumber); 
}

/**
 * 模糊查询
 */
function searchEvent(){
	$('#search').bind('keypress',function(event){                 
         if(event.keyCode == 13) {  
              init(1);
         }  
	});
}

